package studio.xiaoyun.core.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import studio.xiaoyun.core.dao.IFeedbackDao;
import studio.xiaoyun.core.entity.Feedback;
import studio.xiaoyun.core.exception.CoreException;
import studio.xiaoyun.core.exception.ErrorCode;
import studio.xiaoyun.core.service.IFeedbackService;

@Service
public class FeedbackService implements IFeedbackService {

	@Resource
	private IFeedbackDao feedbackDao;
	
	public IFeedbackDao getFeedbackDao() {
		return feedbackDao;
	}

	public void setFeedbackDao(IFeedbackDao feedbackDao) {
		this.feedbackDao = feedbackDao;
	}

	@Override
	public void deleteFeedbackByIDs(List<Long> feedbackIDs) {
		if(feedbackIDs==null || feedbackIDs.isEmpty()) return;
		feedbackDao.deleteByID(feedbackIDs);
	}

	@Override
	public long createFeedback(String title, String text) {
		if(text==null || text.trim().length()==0){
			throw new CoreException(ErrorCode.PARAMETER_ERROR,"内容不能为空!");
		}
		if(title==null || title.trim().length()==0){
			title = "网友";
		}
		Feedback feedback = new Feedback();
		feedback.setText(text.trim());
		feedback.setTitle(title.trim());
		feedback.setCreateDate(new Date());
        long id = feedbackDao.save(feedback);
        return id;
	}

}
